<template>
  <el-popover
    placement="bottom"
    width="200"
    trigger="click">
    <div slot="reference" class="color-btn">
      <div :style="{ backgroundColor: value }" class="color-content"/>
      <i style="font-size: 13px; font-weight: lighter;line-height: 28px; color: #333" class="el-icon-arrow-down icon"/>
    </div>
    <Sketch
      v-model="color"
      @input="colorValueChange($event)"
    />
  </el-popover>
</template>
<script>
import { Sketch } from 'vue-color';

export default {
  components: { Sketch },
  model: {
    prop: 'value',
    event: 'changeValue'
  },
  props: {
    value: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      color: this.value
    };
  },
  methods: {
    colorValueChange() {
      this.$emit('changeValue', this.color.hex8);
    }
  }
};
</script>
<style lang="scss">
.vc-sketch {
  position: relative;
  width: 200px;
  padding: 0 0 0;
  box-sizing: initial;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 0 0 0 transparent, 0 0 0 transparent;
}
.el-popper[x-placement^=bottom] {
  margin-top: 0;
  padding: 0;
}
.el-popover {
  position: absolute;
  background: white;
  min-width: 150px;
  border-radius: 4px;
  border: 0 solid white;
  padding: 0px;
  z-index: 2000;
  color: #606266;
  line-height: 1.4;
  text-align: justify;
  font-size: 14px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,.0);
  word-break: break-all;
}
.el-popover--plain {
  padding: 20px;
}
.color-btn {
  width: 240px;
  height: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid #dddddd;
  border-radius: 4px;
  cursor: pointer;
  .color-content {
    width: 202px;
    height: 24px;
    margin-right: 8px;
    border-radius: 2px;
  }
}
</style>
